package com.zs.backend.modules.dictionaryManagement.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zs.backend.common.api.CommonPage;
import com.zs.backend.common.api.CommonResult;
import com.zs.backend.modules.dictionaryManagement.dto.DictionaryManagementAddOrUptRequest;
import com.zs.backend.modules.dictionaryManagement.dto.DictionaryManagementDTO;
import com.zs.backend.modules.dictionaryManagement.model.DictionaryManagement;
import com.zs.backend.modules.dictionaryManagement.service.DictionaryManagementService;
import com.zs.backend.modules.enterpriseOrder.dto.EnterpriseOrderDTO;
import com.zs.backend.modules.enterpriseOrder.model.EnterpriseOrder;
import com.zs.backend.modules.enterpriseOrder.service.EnterpriseOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.math.BigDecimal;
import java.util.Date;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 字典表 前端控制器
 * </p>
 *
 * @author zs
 * @since 2024-03-23
 */
@RestController
@Api(tags = "字典管理")
@RequestMapping("/dictionaryManagement")
public class DictionaryManagementController {

    @Autowired
    private DictionaryManagementService dictionaryManagementService;

    @ApiOperation("字典管理列表")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public CommonResult<CommonPage<DictionaryManagement>> list(
        @ApiParam(value = "字典类型：多个使用逗号分隔（1:职称专业;2:企业部人员；3：人才部人员；4：收证人；5：人才名称；6：支付类型；7：手机管理人员，8：所属公司；9：职称类型；10：毕业学历；11：类型）",name = "types")
        @RequestParam(value = "types", required = false) String types,

        @ApiParam(value = "名称", name = "dictionaryName")
        @RequestParam(value = "dictionaryName", required = false) String dictionaryName,

        @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
        @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {

        DictionaryManagementDTO dto = DictionaryManagementDTO.builder()
            .dictionaryName(dictionaryName)
            .types(types)
            .build();
        Page<DictionaryManagement> pageList = dictionaryManagementService.list(dto, pageSize,pageNum);
        return CommonResult.success(CommonPage.restPage(pageList));
    }

    @ApiOperation("添加、修改字典")
    @RequestMapping(value = "/addOrUpt", method = RequestMethod.POST)
    public CommonResult addOrUpt(@RequestBody @Valid DictionaryManagementAddOrUptRequest dto) {
        boolean success = dictionaryManagementService.addOrUpt(dto);
        if (success) {
            return CommonResult.success(null);
        }
        return CommonResult.failed();
    }

    @ApiOperation("删除")
    @RequestMapping(value = "/updateDel/{id}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult updateDel(
        @ApiParam(value = "数据id", name = "id")
        @PathVariable Long id) {
        boolean success = dictionaryManagementService.updateDel(id);
        if (success) {
            return CommonResult.success(null);
        }
        return CommonResult.failed();
    }
    

}

